<?php

/**
 * uiGetMainMenu
 * 获取主菜单
 *
 * @return void
 */
function uiGetMainMenu() {
    $menuFileConf = C('MENU_FILE');
    $userType     = C('RUN_LOGIN_USER.type');
    $userType     = empty($userType) || !array_key_exists($userType, $menuFileConf) ? 5 : $userType;
    $menuFile     = $menuFileConf[$userType];

    $menu = include(__DIR__ . "/../Conf/{$menuFile}.php");
    $menuModel = new Common\Model\MenuModel;
    $menuModel->setDao($menu);

    if(!$r = $menuModel->getByPid(0)) {
        return '';
    }

    $html = '<ul>';

    foreach($r as $v) {
        $html .= "<li><a href='javascript:;' mid='{$v['id']}'>{$v['name']}</a></li>";
    }

    $html .= '</ul>';

    return $html;
}

/**
 * uiGetSubMenu
 * 获取所有子菜单及后代菜单
 *
 * @return void
 */
function uiGetSubMenu() {
    $menuFileConf = C('MENU_FILE');
    $userType     = C('RUN_LOGIN_USER.type');
    $userType     = empty($userType) || !array_key_exists($userType, $menuFileConf) ? 5 : $userType;
    $menuFile     = $menuFileConf[$userType];

    $menu  = include(__DIR__ . "/../Conf/{$menuFile}.php");
    $mMenu = new Common\Model\MenuModel;
    $mMenu->setDao($menu);

    $mainMenu = $mMenu->getByPid(0);
    $html = '';

    foreach($mainMenu as $v) {
        if(!$_menu2 = $mMenu->getByPid($v['id'])) {
            continue;
        }

        foreach($_menu2 as $v2) {
            $html .= "<dl mid='{$v['id']}'>";
            $html .= "<dt>{$v2['name']}</dt>";

            if($_menu3 = $mMenu->getByPid($v2['id'])) {
                $html .= '<dd>';

                foreach($_menu3 as $v3) {
                    $html .= "<a href='{$v3['url']}'>{$v3['name']}</a>";
                }

                $html .= '</dd>';
            }

            $html .= '</dl>';
        }
    }

    return $html;
}

/**
 * getSiterIncomeTop10
 * 获取所有站长收入倒序前10名
 * 如果是客服平台登陆时获取的是客服所属站长收入倒序前10名
 *
 * @return void
 */
function getSiterIncomeTop10() {
    $mSiterStats = D2('VSiterStats');
    $day         = date('Y-m-d');
    $r = $mSiterStats->where(array('day' => $day))->order('siter_income DESC')->limit(10)->select();
    
    return empty($r) ? false : $r;
}
